package com.esri.core.internal.tasks.e.a;

import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.EsriServiceException;
import com.esri.core.io.UserCredentials;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

/* loaded from: classes.dex */
public class b extends com.esri.core.internal.tasks.d<f> {
    private static final long serialVersionUID = 1;
    private String a;
    private Map<String, String> b;

    public b(c cVar, String str, UserCredentials userCredentials) {
        this(cVar, str, userCredentials, null);
    }

    public b(c cVar, String str, UserCredentials userCredentials, TaskListener<f> taskListener) {
        super(cVar, str, userCredentials, taskListener);
        this.a = null;
        this.b = null;
        if (this.serviceURL.contains("?")) {
            String[] split = this.serviceURL.split("\\?");
            this.a = split[0];
            if (split.length == 2) {
                String[] split2 = split[1].split("&");
                this.b = new HashMap();
                for (String str2 : split2) {
                    String[] split3 = str2.split("=");
                    this.b.put(split3[0], split3[1]);
                }
            }
        }
        if (cVar == null) {
            throw new EsriServiceException("The WMS get capabilities task requires input parameters");
        }
        if (!cVar.validate()) {
            throw new EsriServiceException("At least one parameter is missing or incorrect. The parameter might be version number, layer names, spatial reference, bounds, width or height. ");
        }
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public f execute() throws Exception {
        InputStreamReader inputStreamReader;
        Map<String, String> generateRequestParams = this.actionInput.generateRequestParams();
        Map<String, String> map = this.b;
        if (map != null) {
            generateRequestParams.putAll(map);
        }
        String str = this.a;
        if (str == null) {
            str = this.serviceURL;
        }
        InputStream c = com.esri.core.internal.io.handler.c.c(str, generateRequestParams, getServiceCredentials());
        XMLReader xMLReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
        a aVar = new a();
        xMLReader.setContentHandler(aVar);
        InputSource inputSource = new InputSource();
        InputStreamReader inputStreamReader2 = null;
        try {
            inputStreamReader = new InputStreamReader(c, "UTF-8");
        } catch (Throwable th) {
            th = th;
        }
        try {
            inputSource.setCharacterStream(inputStreamReader);
            xMLReader.parse(inputSource);
            inputStreamReader.close();
            return aVar.a();
        } catch (Throwable th2) {
            th = th2;
            inputStreamReader2 = inputStreamReader;
            if (inputStreamReader2 != null) {
                inputStreamReader2.close();
            }
            throw th;
        }
    }
}
